package struts.form;

import java.io.File;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

public class Struts_config {
	
	public Struts_config(){
		
	}
	
	public void ddd() throws Exception
	{
		
		SAXBuilder builder = new SAXBuilder();
		Document document = builder.build(new File("src/xml/struts-config.xml"));
		Element root = document.getRootElement();
		
		Element actionforms = root.getChild("formbeans");
		List<Element> forms = actionforms.getChildren();
		
		Element mappings = root.getChild("action-mapping");
		List<Element> actions = mappings.getChildren();
		for(Element form:forms){
			String name = form.getAttributeValue("name");
			String clazz = form.getAttributeValue("class");
			System.out.println("form name=" + name + "||class=" + clazz);			
			
			for(Element action:actions){
				String actioname = action.getAttributeValue("name");
				if (!actioname.equals(name))
				{
					continue;
				}

				String actiontype=action.getAttributeValue("type");
				String actionpath=action.getAttributeValue("path");
				System.out.println("action name=" + name + "||type=" + actiontype + "||path="+actionpath);
				
				List<Element> forwords = action.getChildren();
				for(Element forword:forwords)
				{
					String fname = forword.getAttributeValue("name");
					String fvalue = forword.getAttributeValue("value");
					System.out.println("forword name=" + fname + "||value="+fvalue);
				}
				break;
			}
			System.out.println("========================================");
		}
	}
	
	static public void main(String arg[]) throws Exception
	{
		(new Struts_config()).ddd();
	}
}
